<script setup lang="ts">
import { useChannelStore } from '@/stores/channel';
import type { AxiosRequestData, ChannelRequest, Channels } from '@/types';
import axios from 'axios';
import { onMounted, ref } from 'vue';

const store = useChannelStore()

const list = ref<Channels[]>([])
const getdata = async () => {
  const ref = await axios.get<AxiosRequestData<ChannelRequest<Channels>>>('http://geek.itheima.net/v1_0/channels')
  list.value = ref.data.data.channels
}

onMounted(() => {
  getdata()
})

// defineProps<{ channelId: number }>()
// defineEmits<{ 'changeChannel': [channelId: number] }>()
</script>

<template>
  <div class="channel-nav">
    <nav class="list">
      <a class="item" :class="{ active: store.channelId === item.id }" href="javascript:;" v-for="(item, i) in list"
        :key="item.id" @click="store.updateChannelId(item.id)">
        {{ item.name }}
      </a>
    </nav>
  </div>
</template>